import groovy.json.JsonOutput;

def clone(repo, branch) {
    def credentialsId = 'gitlab-ccc-api-token'

    checkout([$class: 'GitSCM',
              branches: [[name: branch]],
              doGenerateSubmoduleConfigurations: false,
              extensions: [[$class: 'CloneOption', depth: 0, shallow: true, noTags: false],
                           [$class: 'SubmoduleOption',
                            disableSubmodules: false,
                            parentCredentials: true,
                            recursiveSubmodules: true,
                            reference: '',
                            trackingSubmodules: false]],
              submoduleCfg: [],
              userRemoteConfigs: [[credentialsId: credentialsId,
                                   url: "https://gitlab.weike.fm/${repo}"]]])
}

def cleanWorkspace() {
    // clean workspace
    sh 'sudo git clean -fdx'
    deleteDir()
}

def cleanDockerImage(image) {
    sh "docker image rm ${image} || true"
}

return this
